/**
 * 结构类型系统 兼容性
 */

 //接口的兼容性
 //如果传入的变量和声明的类型不匹配，TS会进行兼容性检查
 interface Animal {
   name:string;
   age:number
 }
 interface Person{
   name: string;
   age:number;
   gender: number
 }
 //原理Duck-check 只要目标类型中声明的变量在源头类型中都存在那么就是兼容的
 function getName(animal:Animal):string {
   return animal.name;
 }
 let p:Person = {name:'gc',age:16,gender:1};
getName(p);

//接口的兼容性
//基本类型的兼容性
let num: string|number;
let str: string = 'gg';
num = str;

let num2: {
  toString(): string
}
let str2:string = 'jiagou';
num2 = str2;

//类的兼容性
namespace a {
  class Animal {
    name: string
  }
  class Bird extends Animal {
  }
  let a:Animal;
  a = new Bird();
  
  let b:Bird;
  b = {name: 'bird'};
  // let b:Bird;
  // b = new Animal(); 不行
}

//函数的兼容性
namespace b {
  type sumFunc = (a:number,b:number) => number;
  let sum:sumFunc;
  function f1(a:number,b:number){
    
  }
}









export {};